//
//  UIBarButtonItem+Extension.swift
//  徐工微博
//
//  Created by ahfu on 2017/4/10.
//  Copyright © 2017年 ahfu. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    
    /// 创建 UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title: title
    ///   - fontSize: fontSize,默认16
    ///   - target: target
    ///   - action: action
    ///   - isBack: 是否是返回按钮，如果是加上箭头
    convenience init(title: String, fontSize: CGFloat = 16,target: AnyObject, action: Selector, isBack: Bool = false) {
        let btn = UIButton()
        btn.setTitle(title, for: .normal)
        btn.addTarget(target, action: action, for: .touchUpInside)
        // 大小自适应
        //btn.frame = CGRect(x: 0, y: 0, width: 50, height: 30)
        // 字体颜色
        btn.setTitleColor(UIColor.darkGray, for: .normal)
        btn.setTitleColor(UIColor.orange, for: .highlighted)
        // 设置字体大小
        btn.titleLabel?.font = UIFont.systemFont(ofSize: fontSize)
        //创建
        btn.sizeToFit()

        if isBack {
            btn.setImage(UIImage(named: "navigationbar_back_withtext"), for: .normal)
            btn.setImage(UIImage(named: "navigationbar_back_withtext_highlighted"), for: .highlighted)
            
            btn.sizeToFit()
        }
        self.init(customView: btn)
    }
}
